<?php

require('config/config.php');
include('header.php');
    $utilisateur = $_SESSION['utilisateur'];
	
	$user = new Utilisateur('','','' ,'' ,'', '', '', '', '');

		
	$profiles = Profil::rechercheTout();
	
	if(\Utils\Outils::getValue('envoie')){
	
		if(!empty($_POST['mdp']) && !empty($_POST['confmdp']) && $_POST['mdp'] == $_POST['confmdp']){
			 $mdp = $user->saleMotDePasse($_POST['confmdp']);
		}
        $user->setNomUtilisateur(\Utils\Outils::getValue('nom'));
        $user->setPrenomUtilisateur(\Utils\Outils::getValue('prenom'));
        $user->setLoginUtilisateur(\Utils\Outils::getValue('identifiant'));
        $user->setCourrielUtilisateur(\Utils\Outils::getValue('email'));
        $user->setActiviteUtilisateur(1);
        $user->setMdpUtilisateur($mdp);
        $user->setProfil(Profil::recherche(\Utils\Outils::getValue('profil'), true));
		$user->ajout();

        $message = 'Utilisateur ajouté avec succès';
	}

?>
       <!-- Header -->
    <header class="container_12 " id="header">
        <div class="grid_3 alpha">
            <img src="./stylesheets/images/logo1.png" alt="Logo"/>
        </div>
<?php
    require 'tableauCriticite.php';
?>
    </header>
    <!-- End Header -->
     <div class="clear"></div>
    <section class="content">
<?php
    require 'menu.php';
?>
    <!-- User account -->
        <form class="compte" method="POST" action="">
            <fieldset>
                <legend>Ajouter un nouvel utilisateur</legend><br>
                <?php
                   if (isset($message)) {
                        echo '<p><label class="grid_3" for="message"></label>';
                        echo $message;
                        echo '</p><div class="clear"></div>';
                    }
                ?>
                   <p><label class="grid_3" for="profil">Profil :</label></p>
                		<select class="grid_3" name="profil">
<?php
						foreach($profiles as $profil){
							if( $utilisateur->getProfil()->getId() != $profil->getId()){
								echo "<option value='" . $profil->getId() . "'>" .$profil->getNomProfil()  ."</option>";
							}else{
								echo "<option selected='true' value='" . $profil->getId() . "'>" .$profil->getNomProfil()  ."</option>";
							}
						}
?>
                		</select>
                		<div class="clear"></div>
                    <p><label class="grid_3" for="nom">Nom :</label><input class="grid_3" type="text" name="nom" id="nom"></p><div class="clear"></div>
                    <p><label class="grid_3" for="prenom">Prénom :</label><input class="grid_3" type="text" name="prenom" id="prenom"></p><div class="clear"></div>
                    <p><label class="grid_3" for="identifiant">Identifiant :</label><input class="grid_3" type="text" name="identifiant" id="identifiant"></p><div class="clear"></div>
                    <p><label class="grid_3" for="mdp">Mot de passe :</label><input class="grid_3" type="password" name="mdp" id="mdp"></p><div class="clear"></div>
                    <p><label class="grid_3" for="confmdp"> Confirmer nouveau mot de passe :</label><input class="grid_3" type="password" name="confmdp" id="confmdp"></p><div class="clear"></div>
					<p><label class="grid_3" for="email">E-mail :</label><input class="grid_3" type="text" name="email" id="email"></p><div class="clear"></div>
                </fieldset>

            <input type="submit" name="envoie" value="Ajouter">
        </form>
    </section>
    <!-- End User account -->
    <!-- Footer -->
<?php
    include 'footer.php';
 ?>
    <!-- End Footer -->
</body>
</html>
 